<head>
  <style> body { margin: 0; } </style>

  <script src="//unpkg.com/3d-force-graph"></script>
  <script src="https://unpkg.com/neo4j-driver"></script>
  <!--<script src="../../dist/3d-force-graph.js"></script>-->
</head>

<body>
  <div id="3d-graph"></div>

  <script>
    const driver = neo4j.driver("bolt://demo.neo4jlabs.com", neo4j.auth.basic("gameofthrones", "gameofthrones"),{encrypted: true});
	const session = driver.session({database:"gameofthrones"});
	const start = new Date()
    session
      .run('MATCH (n)-[:INTERACTS1]->(m) RETURN id(n) as source, id(m) as target LIMIT $limit', {limit: neo4j.int(5000)})
      .then(function (result) {
        const links = result.records.map(r => { return {source:r.get('source').toNumber(), target:r.get('target').toNumber()}});        
        session.close();
        console.log(links.length+" links loaded in "+(new Date()-start)+" ms.")
        const ids = new Set()
        links.forEach(l => {ids.add(l.source);ids.add(l.target);});
        const gData = { nodes: Array.from(ids).map(id => {return {id}}), links: links}
        const Graph = ForceGraph3D()(document.getElementById('3d-graph')).graphData(gData);
      })
      .catch(function (error) {
        console.log(error);
      });
  </script>
</body>
